package GUIadapter;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import ModelLayer.Order;
import ModelLayer.SaleOrder;

@SuppressWarnings("serial")
public class SaleOrderModel extends AbstractTableModel
{
	private final String[] columnHeader= {"Ordrenr", "Type", "Dato", "Kunde", "Pris"};
	
	private List<SaleOrder> saleorderList;

	public SaleOrderModel(List<SaleOrder> saleorderList)
	{
		this.saleorderList = saleorderList;
	}
	
	@Override
	public String getColumnName(int column)
	{
		// TODO Auto-generated method stub
		return columnHeader[column];
	}

	@Override
	public int getColumnCount()
	{
		// TODO Auto-generated method stub
		return columnHeader.length; //depends on amount of getters for a supplier eg.: "getName()"... very ugly
	}

	@Override
	public int getRowCount()
	{
		// TODO Auto-generated method stub
		return saleorderList.size();
	}

	@Override
	public Object getValueAt(int row, int col)
	{
		// TODO Auto-generated method stub
		Order order = saleorderList.get(row);
			switch(col)
			{
			case 0:
				return order.getOrdernr();
			case 1:
				return "Salgsordre";
			case 2:
				return order.getDate();
			case 3:
				return order.getCustomer().getName();//ignorer fejlkoden, det virker efter ordren er oprettet
			case 4:
				return order.calculateTotalPrice();
			}
		return null; //should never reach here..!
	}

} //end TableSupplierAdapter